package com.niuke;

import com.pojo.ListNode;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-12-13 01:18:03
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-12-13     张李鑫                     1.0         1.0 Version
 */
public class JZ24 {
    /**
     * 给定一个单链表的头结点pHead，长度为n，反转该链表后，返回新链表的表头。
     */

    public static ListNode ReverseList(ListNode head) {
        if (head == null) {
            return null;
        }
        if (head.next == null) {
            return head;
        }

        ListNode cur = null;
        ListNode next = null;

        while (head != null) {
            cur=head.next;
            head.next=next;
            next=head;
            head=cur;
        }
        return next;
    }

    public static void main(String[] args) {
        ListNode listNode=new ListNode(1);
        ListNode listNode1=new ListNode(2);
        ListNode listNode2=new ListNode(3);
        ListNode listNode3=new ListNode(4);


        listNode.next=listNode1;
        listNode1.next=listNode2;
        listNode2.next=listNode3;

        ListNode listNode4 = ReverseList(listNode);
        System.out.println(123);

    }
}